package com.qf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 生成消费者登录验证码
 * @author 千锋健哥
 */
@WebServlet("/code")
public class CodeController extends BaseController{

    /**
     * 生成验证码图片
     * @param request
     * @param response
     */
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //创建验证码对象
        ValidateCode validateCode = new ValidateCode(120, 30, 4, 20);
        //生成验证码
        String code = validateCode.getCode();
        //验证码保存在session中
        request.getSession().setAttribute("code", code);
        //通过流将验证码写回到页面
        validateCode.write(response.getOutputStream());
    }
}
